package com.flying.flow.model;

import com.flying.common.util.Codes;
import com.flying.framework.annotation.ConstantEnum;
import com.flying.framework.annotation.Param;
import com.flying.framework.annotation.Property;
import com.flying.framework.data.Data;
import com.flying.framework.data.DataSerializable;
import com.flying.framework.metadata.Meta;

@SuppressWarnings("serial")
@Meta(id="f_node",title="流程节点", table="f_node", primaryKeys={"node_id"})
public class Node extends Data implements DataSerializable {
	public final static String ENTITY_NAME = "f_node";

	public final static String NODE_ID = "node_id";
	public final static String FLOW_DEF_ID = "flow_def_id";
	public final static String NAME = "name";
	public final static String REMARKS = "remarks";
	public final static String PRIORITY_LEVEL = "priority_level";
	public final static String EMERGENCY_LEVEL = "emergency_level";
	public final static String TASK_START_TYPE = "task_start_type";
	public final static String TASK_MODE = "task_mode";
	public final static String ALLOW_SPLIT = "allow_split";
	public final static String ROUTE_MODE = "route_mode";
	public final static String FINISH_CONDITION = "finish_condition";
	public final static String EVENT_ON_LEAVE = "event_on_leave";
	public final static String EVENT_ON_ENTER = "event_on_enter";
	public final static String PARTICIPANT_TYPE = "participant_type";
	public final static String PARTICIPANTS_SOURCE = "participants_source";
	public final static String EXPECT_TIME = "expect_time";
	public final static String FORM_ACTION = "form_action";
	public final static String FORM_CODE = "form_code";
	public final static String FORM_DATA = "form_data";
	public final static String NODE_TYPE = "node_type";
	
	public enum NodeType implements ConstantEnum<Integer> {
		START(0, "开始节点"), NORMAL(1, "普通节点"), AUTO(2, "自动节点"), END(9, "终止节点");
		
		public final int type;
		public final String remarks;
		
		NodeType(int type, String remarks) {
			this.type = type;
			this.remarks = remarks;
		}
		@Override
		public Integer value() {
			return type;
		}
		@Override
		public String text() {
			return remarks;
		}
	}
	
	public enum AllowSplit implements ConstantEnum<Integer> {
		NOT_ALLOW(0, "不允许"), ALLOW(1, "允许");
		
		public final int type;
		public final String remarks;
		
		AllowSplit(int type, String remarks) {
			this.type = type;
			this.remarks = remarks;
		}
		@Override
		public Integer value() {
			return type;
		}
		@Override
		public String text() {
			return remarks;
		}
	}
	
	public enum FinishCondition implements ConstantEnum<Integer> {
		NONE(0, "无需完成"), ONE(1, "一个完成"), MULTITUDE(2, "多数完成"), ALL(3, "所有完成");
		
		public final int type;
		public final String remarks;
		
		FinishCondition(int type, String remarks) {
			this.type = type;
			this.remarks = remarks;
		}
		@Override
		public Integer value() {
			return type;
		}
		@Override
		public String text() {
			return remarks;
		}
	}
	
	public enum TaskStartType implements ConstantEnum<Integer> {
		AUTO(0, "自动启动"), MANUAL(1, "手动启动");
		
		public final int type;
		public final String remarks;
		
		TaskStartType(int type, String remarks) {
			this.type = type;
			this.remarks = remarks;
		}
		@Override
		public Integer value() {
			return type;
		}
		@Override
		public String text() {
			return remarks;
		}
	}
	
	public enum TaskMode implements ConstantEnum<Integer> {
		ONE_TASK_ONE_PARTICIPANT(1, "指派任务"), //为每一个参与者分配一个任务，任务创建后即为已分配状态
		ONE_TASK_ONE_OF_PARTICIPANTS(2, "指派任务"), //创建一个待分配的任务，分配人员为资源池中的人员
		SEIZE(3, "抢占"),  //为当前环节创建一个任务，所有参与者抢占任务
		INHERIT_FROM_PRE_NODE(4, "继承"); //继承上一个环节的任务数量和处理人
		
		public final int type;
		public final String remarks;
		
		TaskMode(int type, String remarks) {
			this.type = type;
			this.remarks = remarks;
		}
		@Override
		public Integer value() {
			return type;
		}
		@Override
		public String text() {
			return remarks;
		}
	}
	
	public enum RouteMode implements ConstantEnum<Integer> {
		AUTO(0, "自动路由"), //根据Transition.Condition定义计算路由
		MANUAL(1, "人工路由"); //处理界面指定路由
		
		public final int type;
		public final String remarks;
		
		RouteMode(int type, String remarks) {
			this.type = type;
			this.remarks = remarks;
		}
		@Override
		public Integer value() {
			return type;
		}
		@Override
		public String text() {
			return remarks;
		}
	}
	
	public enum EmergencyLevel implements ConstantEnum<Integer> {
		NORMAL(1, "一般"), MIDDLE(2, "中等"), EMERGENCY(3, "紧急");
		
		public final int type;
		public final String remarks;
		
		EmergencyLevel(int type, String remarks) {
			this.type = type;
			this.remarks = remarks;
		}
		@Override
		public Integer value() {
			return type;
		}
		@Override
		public String text() {
			return remarks;
		}
	}
	
	public enum PriorityLevel implements ConstantEnum<Integer> {
		LOW(0, "低级"), MIDDLE(2, "中等"), HIGH(3, "高级");
		
		public final int type;
		public final String remarks;
		
		PriorityLevel(int type, String remarks) {
			this.type = type;
			this.remarks = remarks;
		}
		@Override
		public Integer value() {
			return type;
		}
		@Override
		public String text() {
			return remarks;
		}
	}
	
	
	@Param(value=EVENT_ON_LEAVE,   required=false,   maxlength=30,	desc="结束事件" )
	private String eventOnLeave;
	
	@Param(value=EVENT_ON_ENTER,   required=false,   maxlength=30,	desc="开始事件" )
	private String eventOnEnter;
	
	@Param(value=EXPECT_TIME,   required=false,   	desc="期望完成时间" )
	private String expectTime;
	
	@Param(value=FINISH_CONDITION,   required=false,   	desc="完成条件" )
	private Integer finishCondition;
	
	@Param(value=FLOW_DEF_ID,   required=true,   	desc="流程定义ID" , 
			props= {@Property(name="type",value="hidden")})
	private Long flowDefId;
	
	@Param(value=FORM_ACTION,   required=false,   maxlength=50,	desc="表单行为" )
	private String formAction;
	
	@Param(value=FORM_CODE,   required=false,   maxlength=20,	desc="表单代码" )
	private String formCode;
	
	@Param(value=FORM_DATA,   required=false,   maxlength=20,	desc="表单数据" )
	private String formData;
	
	@Param(value=NAME,   required=true,   maxlength=100,	desc="名称" )
	private String name;
	
	@Param(value=NODE_ID,   required=true,   desc="节点ID" , generator=Codes.AUTO_INCREMENT, 
			props= {@Property(name="type",value="hidden")})
	private Long nodeId;
	
	@Param(value=NODE_TYPE,   required=false,	desc="节点类型" )
	private Integer nodeType;
	
	@Param(value=PARTICIPANT_TYPE,   required=false,   maxlength=20,	desc="执行人类型" )
	private String participantType;
	
	@Param(value=PARTICIPANTS_SOURCE,   required=false,   maxlength=100,	desc="执行人来源" )
	private String participantsSource;
	
	@Param(value=PRIORITY_LEVEL,   required=false,   enumClass = PriorityLevel.class,	desc="优先级别" ,
			props= {@Property(name="type",value="combobox"), 
					@Property(name="valueField",value="value"), 
					@Property(name="textField",value="text"), 
					@Property(name="url",value="/flow/enums/findEnums.do?$value=rows&class=com.flying.flow.model.Node$PriorityLevel")} )
	private Integer priorityLevel;
	
	@Param(value=EMERGENCY_LEVEL,   required=false,   enumClass = EmergencyLevel.class,	desc="紧急程度",
			props= {@Property(name="type",value="combobox"), 
					@Property(name="valueField",value="value"), 
					@Property(name="textField",value="text"), 
					@Property(name="url",value="/flow/enums/findEnums.do?$value=rows&class=com.flying.flow.model.Node$EmergencyLevel")} )
	private Integer emergencyLevel;
	
	@Param(value=REMARKS,   required=false,   maxlength=1000,	desc="说明" )
	private String remarks;
	
	@Param(value=TASK_MODE,   required=false,   enumClass=TaskMode.class,	desc="任务执行模式" )
	private Integer taskMode;
	
	@Param(value=ALLOW_SPLIT,   required=false,   enumClass=AllowSplit.class,	desc="是否允许拆分任务" )
	private Integer allowSplit;
	
	@Param(value=ROUTE_MODE,   required=false,   enumClass=RouteMode.class,	desc="路由模式" )
	private Integer routeMode;
	
	@Param(value=TASK_START_TYPE,   required=false,   enumClass=TaskStartType.class,	desc="任务启动类型" )
	private Integer taskStartType;
	
	
	public Integer getEmergencyLevel() {
		return this.emergencyLevel;
	}
	
	public void setEmergencyLevel(Integer emergencyLevel) {
		this.emergencyLevel = emergencyLevel;
	}
	
	public Integer getFinishCondition() {
		return this.finishCondition;
	}
	
	public void setFinishCondition(Integer finishCondition) {
		this.finishCondition = finishCondition;
	}
	
	public Long getFlowDefId() {
		return this.flowDefId;
	}
	
	public void setFlowDefId(Long flowDefId) {
		this.flowDefId = flowDefId;
	}
	
	public String getFormAction() {
		return this.formAction;
	}
	
	public void setFormAction(String formAction) {
		this.formAction = formAction;
	}
	
	public String getFormCode() {
		return this.formCode;
	}
	
	public void setFormCode(String formCode) {
		this.formCode = formCode;
	}
	
	public String getFormData() {
		return formData;
	}

	public void setFormData(String formData) {
		this.formData = formData;
	}

	public String getName() {
		return this.name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getExpectTime() {
		return expectTime;
	}

	public void setExpectTime(String expectTime) {
		this.expectTime = expectTime;
	}

	public Long getNodeId() {
		return this.nodeId;
	}
	
	public void setNodeId(Long nodeId) {
		this.nodeId = nodeId;
	}
	
	public Integer getNodeType() {
		return this.nodeType;
	}
	
	public void setNodeType(Integer nodeType) {
		this.nodeType = nodeType;
	}
	
	public String getEventOnLeave() {
		return eventOnLeave;
	}

	public void setEventOnLeave(String eventOnLeave) {
		this.eventOnLeave = eventOnLeave;
	}

	public String getEventOnEnter() {
		return eventOnEnter;
	}

	public void setEventOnEnter(String eventOnEnter) {
		this.eventOnEnter = eventOnEnter;
	}

	public Integer getTaskStartType() {
		return taskStartType;
	}

	public void setTaskStartType(Integer taskStartType) {
		this.taskStartType = taskStartType;
	}

	public String getParticipantType() {
		return this.participantType;
	}
	
	public void setParticipantType(String participantType) {
		this.participantType = participantType;
	}
	
	public String getParticipantsSource() {
		return this.participantsSource;
	}
	
	public void setParticipantsSource(String participantsSource) {
		this.participantsSource = participantsSource;
	}
	
	public Integer getPriorityLevel() {
		return this.priorityLevel;
	}
	
	public void setPriorityLevel(Integer priorityLevel) {
		this.priorityLevel = priorityLevel;
	}
	
	public String getRemarks() {
		return this.remarks;
	}
	
	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}
	
	public Integer getTaskMode() {
		return this.taskMode;
	}
	
	public void setTaskMode(Integer taskMode) {
		this.taskMode = taskMode;
	}

	public Integer getAllowSplit() {
		return allowSplit;
	}

	public void setAllowSplit(Integer allowSplit) {
		this.allowSplit = allowSplit;
	}

	public Integer getRouteMode() {
		return routeMode;
	}

	public void setRouteMode(Integer routeMode) {
		this.routeMode = routeMode;
	}
	

}